package com.jessehu.xutilstest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import org.xutils.x;

public class MainActivity extends AppCompatActivity {

    private MainActivity TAG;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //实例化XUtiles，使它可以在整个项目中使用
        x.Ext.init(this.getApplication());

        TAG = this;

        //功能名称
        String[] funcs = {"http","download","upload","imageload","db"};

        ListView funcListView = (ListView) findViewById(R.id.lv_main_functions);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, funcs);
        funcListView.setAdapter(adapter);
        funcListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                switch (position){
                    case 0:
                        intent.setClass(TAG, HttpTestActivity.class);
                        break;
                    case 1:
                        intent.setClass(TAG, DownloadTestActivity.class);
                        break;
                    case 2:
                        intent.setClass(TAG,UploadTestActivity.class);
                        break;
                    case 3:
                        intent.setClass(TAG, ImageLoaderActivity.class);
                        break;
                    case 4:
                        intent.setClass(TAG, DBTestActivity.class);
                        break;
                    default:
                        return;
                }
                startActivity(intent);
            }
        });
    }
}
